# from app.databases import db_analytics
from app.databases import db_main

# class UserAnalytics(db_analytics.Model):
#     __bind_key__ = 'analytics'  # 绑定到分析数据库
#     __tablename__ = 'user_analytics'
#
#     id = db_analytics.Column(db_analytics.Integer, primary_key=True)
#     user_id = db_analytics.Column(db_analytics.Integer, nullable=False)
#     last_login = db_analytics.Column(db_analytics.DateTime)
#     login_count = db_analytics.Column(db_analytics.Integer, default=0)
#
#     def to_dict(self):
#         return {
#             'user_id': self.user_id,
#             'last_login': self.last_login.isoformat() if self.last_login else None,
#             'login_count': self.login_count
#         }


class UserAnalytics(db_main.Model):
    __bind_key__ = 'analytics'  # 绑定到分析数据库
    __tablename__ = 'sys_user'

    id = db_main.Column(db_main.Integer, primary_key=True)
    user_id = db_main.Column(db_main.Integer, nullable=False)
    last_login = db_main.Column(db_main.DateTime)
    login_count = db_main.Column(db_main.Integer, default=0)
    user_name = db_main.Column(db_main.String(80), unique=True, nullable=False)

    def to_dict(self):
        return {
            'user_id': self.user_id,
            'user_name':self.user_name,
            'last_login': self.last_login.isoformat() if self.last_login else None,
            'login_count': self.login_count
        }